package com.cloud.edu.sys.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.edu.sys.dao.UserRoleMapper;
import com.cloud.edu.sys.model.UserRole;
import com.cloud.edu.sys.service.SysUserRoleService;

import java.util.ArrayList;
import java.util.List;



/**
 * 用户与角色对应关系
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年9月18日 上午9:45:48
 */
@Service("sysUserRoleService")
public class SysUserRoleServiceImpl implements SysUserRoleService {
	
	@Autowired
	private UserRoleMapper userRoleMapper;

	@Override
	public void saveOrUpdate(Long userId, List<Long> roleIdList) {
		//先删除用户与角色关系
//		this.deleteByMap(new MapUtils().put("user_id", userId));

		if(roleIdList == null || roleIdList.size() == 0){
			return ;
		}

		//保存用户与角色关系
		List<UserRole> list = new ArrayList<>(roleIdList.size());
		for(Long roleId : roleIdList){
			UserRole record = new UserRole();
//			record.setUserId(userId);
//			record.setRoleId(roleId);

			list.add(record);
			userRoleMapper.insertSelective(record);
		}
	}

	@Override
	public List<Long> queryRoleIdList(Long userId) {
//		return record.queryRoleIdList(userId);
		return null;
	}

	@Override
	public int deleteBatch(Long[] roleIds){
//		return baseMapper.deleteBatch(roleIds);
		return 0;
	}
}
